package common

import (
	"github.com/gin-gonic/gin"
	"net/http"
)

type Response struct {
	Msg  string
	Code int32
	Data interface{}
}

func (res Response) Format(c *gin.Context, msg ...string) {
	l := len(msg)
	if l != 0 {
		res.Code = 1
		res.Msg = msg[0]
	} else {
		res.Msg = "成功"
	}
	c.JSON(http.StatusOK, gin.H{
		"Code": res.Code,
		"Msg":  res.Msg,
		"Data": res.Data,
	})
}
